<?php


if(!function_exists('checkForData')){
    /**
     * @throws \App\Exceptions\SysExceptions
     */
    function checkForData($values = [], $tips = [], $datas = [])
    {
        foreach ($values as $key=>$v){
            if(!checkIsHasField($datas,$values[$key])){
                throw new \App\Exceptions\SysExceptions($tips[$key]);
            }
        }
    }
}

if(!function_exists('checkIsHasField')){
    /**
     * desc:检测数据
     * admin
     * email:
     * @param array $params
     * @param string $field
     * @return bool
     */
    function checkIsHasField($params = [],$field = ''): bool
    {
        return isset($params[$field]) && $params[$field] !== '' && !is_null($params[$field]);
    }
}
if(!function_exists('isPost')){
    /**
     * desc:检测数据
     * admin
     * email:
     * @return bool
     */
    function isPost(): bool
    {
        return request()->isMethod('post');
    }
}

if(!function_exists('getIsHasPage')){
    /**
     * desc:检测数据
     * admin
     * email:
     * @return bool
     */
    function getIsHasPage(): bool
    {
        return request()->has('page');
    }
}


if (!function_exists('makeOrderNo')){
    //生成订单号
    function makeOrderNo(): string
    {
        $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
        $orderSn =
            $yCode[intval(date('Y')) - 2017] . strtoupper(dechex(date('m'))) . date(
                'd') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf(
                '%02d', rand(0, 99));
        return $orderSn;
    }
}

if(!function_exists('getUserToken')){
    /**
     * desc:检测数据
     * admin
     * email:
     * @return bool
     */
    function getUserToken(){
        return request()->user_id;
    }
}

if(!function_exists('getAdminId')){
    /**
     * desc:检测数据
     * admin
     * email:
     * @return bool
     */
    function getAdminId()
    {
        return request()->user_id;
    }
}


